<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class AlidayuController extends Controller
{
   public function fasong(Request $request , $mobile){
        $res = DB::table('users')->where('name',$mobile)->first();
        $tel = $res->mobile;
        // dd($tel);

        require(base_path()."/vendor/alidayu/TopSdk.php");

        $appkey = '23414403';
        $secret = '3b5a466fed6103f97d69012a24e392c8';
        $rand = mt_rand(1000,9999);

        //将生成的随机数写入session中
        $request->session()->put('smcode',$rand);

        $c = new \TopClient;
        $c->appkey = $appkey;
        $c->secretKey = $secret;
        $req = new \AlibabaAliqinFcSmsNumSendRequest;
        $req->setExtend("123456");
        $req->setSmsType("normal");
        $req->setSmsFreeSignName("李飞");
        $req->setSmsParam("{\"code\":\"{$rand}\",\"product\":\"李飞\"}");
        $req->setRecNum($tel);
        $req->setSmsTemplateCode("SMS_12526384");
        echo $c->execute($req)?$rand:0;
   }

   public function yanzheng(Request $req){
    echo $req->session()->get('smcode');
   }
}
